/*
 * DepartamentoDAO.java
 *
 * Created on 5 de octubre de 2007, 09:57 AM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.src.computec.radar.services.utilities.dao;

import com.src.computec.radar.base.dao.GenericDAO;
import com.src.computec.radar.base.dao.exception.DAOException;
import com.src.computec.radar.services.base.constantes.ConstantesGenerales;
import com.src.computec.radar.services.utilities.dto.DepartamentoDto;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author aocampo
 */
public class DepartamentoDAO extends GenericDAO implements BaseDepartamentoDAO {
    
    /** Creates a new instance of DepartamentoDAO */
    public DepartamentoDAO() {
    }
    
    public List getDepartamentos() throws DAOException {
        List listDepartamentos = new ArrayList();
        Connection con = null;
        PreparedStatement statement = null;
        ResultSet rs = null;
        try {
            con = getConnectionDB2();
            statement = con.prepareStatement("SELECT CODIGO_DEPARTAMENTO, NOMBRE_DEPARTAMENTO " +
                                             "FROM " + ConstantesGenerales.getInstance().SCHEMA + ".DEPARTAMENTO " +
                                             "ORDER BY NOMBRE_DEPARTAMENTO ASC");
            rs = statement.executeQuery();
            while (rs.next()) {
                int indice = 0;
                DepartamentoDto departamentoDto = new DepartamentoDto();
                departamentoDto.setCodigoDepartamento(rs.getString(++indice));
                departamentoDto.setNombreDepartamento(rs.getString(++indice));
                listDepartamentos.add(departamentoDto);
            }
        } 
        catch (SQLException e) {
            throw new DAOException("DepartamentoDAO:getDepartamentos: " + e.toString(), e);
        }
        finally {
            closeConnection(con, statement, rs);
        }
        return listDepartamentos;
    }
}